********************************************************************************
* scatter of margin lending rates and funding rates
********************************************************************************

use "build/output/main_panel.dta", clear
keep if coin == "USDT"

preserve
tempfile temper
binscatter funding_apr margin_aprFTX, nq(50) savedata("analysis/output_figures/figure_funding_vs_lending_data") replace
import delimited using "analysis/output_figures/figure_funding_vs_lending_data.csv", clear


two (scatter margin_apr funding_apr, xtitle("Perpetual Future Funding Rate (Percent, annualized)") subtitle("USDT Margin Lending Rate (Percent, annualized)",  orientation(horizontal)  bexpand justification(left)) plotregion(margin(medium))  ytitle("") scale(*1.25)) ///
	(lfit margin_apr funding_apr, lcolor(gs12)), legend(off)
gr export "analysis/output_figures/scatter_funding_lending_ftx.pdf", replace
restore

// delete temporary files
erase "analysis/output_figures/figure_funding_vs_lending_data.csv"
erase "analysis/output_figures/figure_funding_vs_lending_data.do"
